<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="../base.jsp" %>   
 
<s:if test="#attr.productId!=null">
	<s:set var="productId" value="#attr.productId"></s:set>
</s:if>
<s:if test="#attr.productId==null">
	<s:set var="productId" value="#parameters.productId[0]"></s:set>
</s:if>

<sys:genericTag4o 
	methodName="queryProductDetailPriceTitleAll" 
	className="com.wxy.controller.taglib.ProductTag" 
	id="productDetailPriceTitleDtoList">
	<sys:columnTag columnName="productId" columnValue="${attr.productId}"/>
</sys:genericTag4o>	 

<sys:genericTag4o 
    methodName="queryProductSonListByProductId" 
    className="com.wxy.controller.taglib.ProductTag" 
    id="productSonList">
    <sys:columnTag columnName="productId" columnValue="${attr.productId}"/>
</sys:genericTag4o>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>	
<link href="../css/main.css" rel="stylesheet" type="text/css" >
<link href="../css/table.css" rel="stylesheet" type="text/css" >
<link rel="stylesheet" type="text/css" href="${path}/js/jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${path}/js/jquery/easyui/themes/icon.css">

<script type="text/javascript" src="${path}/js/jquery/easyui/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../js/jquery.select.js"></script>
<script type="text/javascript" src="js/productAdd.js"></script>
<script type="text/javascript" src="${path}/js/jquery/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${path}/js/jquery/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
function inAmount(o){
	if(o.value == 0){
	    o.value = "";
	}
	
	o.value=o.value.replace(/\D/g,'');
	var amountSource = $('input:text[name="amountStore"]').attr("text");
	//var amountSource = $('amountStore').attr("text");
	if(o.value ==null || o.value=='' || o.value=='0'){
		$('input:text[name="amountStore"]').val(amountSource);
        return ; 
    }
	//alert(amountSource);
	var amountNew = Number(amountSource)+Number(o.value);
	$('input:text[name="amountStore"]').val(amountNew);
	//$('amountStore').val(amountNew);
}


function blockChar(oText){
    sChar = oText.getAttribute("validchar");    
    ddd = String.fromCharCode(window.event.keyCode);     
    var res = sChar.indexOf(ddd) > -1;     
    return res || window.event.ctrlKey;    
}

function radiodata(o){
     var position = "";
     var productSonStr = "";
     for(var i=0;i<array.length;i++){ 
                    
     var val=$('input:radio[name="'+this.array[i]+'"]:checked').val(); 
     var text = $('input:radio[name="'+this.array[i]+'"]:checked').attr("text");

     position = position+val+",";
     productSonStr = productSonStr + text +",";
     
     if(val == null) {
          alert("请选择"+array1[i]+"的值");
          return;
          }
       }
       $('input:hidden[name="position"]').val(position);
       $('input:hidden[name="productSonStr"]').val(productSonStr);

       //alert($('#saveEditBtnId').val());
       
       $('#saveEditBtnId').val('处理中..');
       $("#saveEditBtnId").attr({"disabled":"disabled"});
       
       $('#formProductStore').submit();
}

</script>
                
</head>
<body class="font14">
	<table width="100%">
		<tr>
			<td valign="top"  width="200px">
				<%@include file="productAddStep1.jsp" %>
				<script type="text/javascript">
				$(function(){
					$("#productAddStep_1_2>a").css("color","red");
				});
				$("#productAddStep_1_2>a").css("color","red");
				</script>					
			</td>
			<td valign="top"  width="600px">
			<s:if test="#attr.result!=null">
                    <table class="table1" width="100%" cellpadding="0" cellspacing="0" >    
                        <thead>
                            <tr style="background-color: #DEE9FB; color: #15428B;">
                                <td align="center">
                                    <strong>操作结果</strong>
                                </td>
                            </tr>
                        </thead> 
                        <tr>
                            <td><font color="red"><s:property value="#attr.result"/></font> </td>
                        </tr>
                    </table>
                 <br/> 
             </s:if> 
			<s:form  id="formProductStore" action="product!addProductSon.action" name = "form1" method="post" namespace="/admin123/product" theme="simple">
				<table class="table1" align="center" width="100%" cellpadding="0" cellspacing="0">
					<thead>
						<tr style="background-color: #DEE9FB; color: #15428B;">
							<td colspan="2" align="center">
								<strong>商品进货明细标签 </strong>
								<input type="hidden" id="productId" name="productId" value="${attr.productId}">
							</td>
						</tr>
					</thead>
	                <tr>
	                   <td>
	                    <% int i=0; %>
	                    <script type="text/javascript">
	                    var array = new Array();
	                    var array1 = new Array();
	                    </script>
	                   </td>
	                </tr>
                    <s:iterator var="titleDto" value="#attr.productDetailPriceTitleDtoList" status="st">
                        <tr> 
                            <td width="80px">
                                <s:property value="title" />
		                        <script type="text/javascript">
		                        array1[<%=i%>] = '${titleDto.title}';
		                        array[<%=i++%>]='radio_${titleDto.id}';
		                       
		                        </script>
                            </td>
                            <td>
                                <s:iterator value="productDetailPriceValueDtoList">
                                <div style="width: 120px; float: left;">
                                    <input type="radio" name="radio_${titleDto.id}" value="${id}" text="${description}"/>
                                    <s:property value="description"/>
                                </div>                                  
                                </s:iterator>
                            </td>
                        </tr> 
                    </s:iterator>
                    <tr>
                    	<td colspan="10"> 
                    		<table class="table1" style="margin: 5px 0;" align="center" width="100%" cellpadding="0" cellspacing="0" >
		                        <tr>
		                        	<td colspan="4" align="center"> <strong>进货信息 </strong> </td>          
		                        </tr>
		                        <tr>
		                            <td width="15%">供货商</td>
		                            <td width="35%" ><input type="text" name="agent" value="" maxlength="50"/></td>
		                            
		                            <td width="15%">供货日期</td>
		                            <td width="35%" ><input type="text" name="agentDate" id="agentDate" class="easyui-datebox" maxlength="20"/></td>
		                        </tr>
		                        <tr>
		                            <td width="15%">采购员</td>
		                            <td width="35%"><input type="text" name="dealer" value=""  maxlength="20"/></td>
		                        
		                            <td width="15%">进价</td>
		                            <td width="35%">
		                            <input type="text" name="inPriceYuan" id="inPriceYuan" value="0" maxlength="14" 
		                                class="easyui-numberbox"
		                                min="0" 
                                        max="99999999999999" 
                                        precision="2" 
                                       />元</td>
		                        </tr>
		                        <tr>
		                            <td>市场价</td>
		                            <td><input type="text" name="marketPriceYuan" id="marketPriceYuan" value="0" maxlength="14" 
		                                class="easyui-numberbox"
                                        min="0" 
                                        max="99999999999999" 
                                        precision="2" 
                                        invalidMessage="单位'元',如100、 95.5、 95.55等 "
		                                  />元</td>
		                            
		                            <td>商城价</td>
		                            <td><input type="text" name="productPriceYuan" id="productPriceYuan" value="0" maxlength="14"
		                                class="easyui-numberbox"
                                        min="0" 
                                        max="99999999999999" 
                                        precision="2" 
                                        required="true"
                                        invalidMessage="单位'元',如100、 95.5、 95.55等 "
		                            />元</td>
		                        </tr>
		                        <tr>
                                    <td>商品数量</td>
                                    <td width="35%">
                                    <input type="text" text = "0" name="amountStore" id ="amountStore" value="0" maxlength="9" validchar="0123456789" onkeypress="return blockChar(this)" onpaste="return false"/>
                                    
                                    <td>描述</td>
                                    <td><input type="text" name="storeAddress" value="" maxlength="50"/></td>
                                </tr>
       
		                        <tr>
		                            <td><input type="hidden" name="position"/></td>
		                            <td><input type="hidden" name="productSonStr"/></td>
		                        </tr>
		              		  </table>
                    	</td>
                    </tr>
                    <tr>
                        <td colspan="10"> 
                        <table class="table2" style="margin: 5px 0;" align="center" width="100%" cellpadding="0" cellspacing="0" >
                            <tr>
                            <td colspan="2">本次进货</td>
                            <td colspan="3"><input type="text" name="amountIn" value="0" maxlength="9" onafterpaste="javascript:inAmount(this)" onkeyup="javascript:inAmount(this)"  maxlength="7"/>
                            <td colspan="4" align="center"><input type="button" id="saveEditBtnId" value="保存/修改"  onclick="javascript:radiodata(this)" /></td>
                            </tr>
                        </table>
                        </td>
                    </tr>
			     </table>
                <br/>
			  </s:form>	
			  
              <table id="productSonListTable" class="table1" width="100%" cellpadding="0" cellspacing="0" style="">    
                   <thead>
                        <tr style="background-color: #DEE9FB; color: #15428B;">
                            <td colspan="10" align="center">
                                 <strong>商品分类显示</strong>
                            </td>
                         </tr>
                    </thead> 
                    <tr>
                           <td align="center">标签信息</td>
                           <td align="center">进价</td>
                           <td align="center">市场价</td>
                           <td align="center">本网价</td>
                           <td align="center">库存总数</td>
                           <td align="center">有效库存</td>
                           <td align="center">操作</td>
                    </tr>
                    <s:iterator var="productSonDto" value="#attr.productSonList">
                    <tr id="${id}" name1="sonTr" style="cursor: pointer;">
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="productSonStrShow"/></td>
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="inPriceYuan"/></td>
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="marketPriceYuan"/></td>
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="productPriceYuan"/></td>
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="amountStore"/></td>
                      <td id="${id}" onclick="javascript:queryProductSonById(this)"><s:property value="amountAvailable"/></td>
                      <td>
                         <a id="deleteSelected_Filter" 
	                         onclick="deleteSelected(${id});" 
	                         class="easyui-linkbutton" 
	                         data-options="plain:true,iconCls:'icon-cancel'"></a>
                      </td>
                     </tr>                               
                   </s:iterator>
              </table>   
			</td>
			<td valign="top" >
				<jsp:include page="productInfo.jsp">
					<jsp:param name="productId" value="${attr.productId}" />
				</jsp:include>
			</td>
		</tr>
	</table>
	<s:form name="productSonForm"  id = "productSonForm" action="product!deleteProductSon.action" namespace="/admin123/product" theme="simple">
	   <input type="hidden" name="productSonId" id="productSonId"/>
	   <input type="hidden" id="productId" name="productId" value="${attr.productId}">
	</s:form>
    <script type="text/javascript">
    function deleteSelected(id){
        if(!confirm('确定删除吗？')){
            return false;
        }
        $('#productSonId').val(id);
        $('#productSonForm').submit();
    }
    //xxx!delete.action?productSonId=${id}
    </script>
</body>
</html>